package com.ruoyi.web.controller.system;

import java.util.List;
import java.util.Arrays;

import lombok.RequiredArgsConstructor;
import javax.validation.constraints.*;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.vo.ZsyyOrderProductVo;
import com.ruoyi.system.bo.ZsyyOrderProductQueryBo;
import com.ruoyi.system.bo.ZsyyOrderProductAddBo;
import com.ruoyi.system.bo.ZsyyOrderProductEditBo;
import com.ruoyi.system.service.IZsyyOrderProductService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import springfox.documentation.annotations.ApiIgnore;

/**
 * 订单关联产品Controller
 *
 * @author wangghua
 * @date 2021-07-14
 */
@ApiIgnore
@Api(value = "订单关联产品控制器", tags = {"订单关联产品管理"})
@RequiredArgsConstructor(onConstructor_ = @Autowired)
@RestController
@RequestMapping("/system/orderProduct")
public class ZsyyOrderProductController extends BaseController {

    private final IZsyyOrderProductService iZsyyOrderProductService;

    /**
     * 查询订单关联产品列表
     */
    @ApiOperation("查询订单关联产品列表")
    @PreAuthorize("@ss.hasPermi('system:orderProduct:list')")
    @GetMapping("/list")
    public TableDataInfo<ZsyyOrderProductVo> list(@Validated ZsyyOrderProductQueryBo bo) {
        return iZsyyOrderProductService.queryPageList(bo);
    }

    /**
     * 导出订单关联产品列表
     */
    @ApiOperation("导出订单关联产品列表")
    @PreAuthorize("@ss.hasPermi('system:orderProduct:export')")
    @Log(title = "订单关联产品", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult<ZsyyOrderProductVo> export(@Validated ZsyyOrderProductQueryBo bo) {
        List<ZsyyOrderProductVo> list = iZsyyOrderProductService.queryList(bo);
        ExcelUtil<ZsyyOrderProductVo> util = new ExcelUtil<ZsyyOrderProductVo>(ZsyyOrderProductVo.class);
        return util.exportExcel(list, "订单关联产品");
    }

    /**
     * 获取订单关联产品详细信息
     */
    @ApiOperation("获取订单关联产品详细信息")
    @PreAuthorize("@ss.hasPermi('system:orderProduct:query')")
    @GetMapping("/{id}")
    public AjaxResult<ZsyyOrderProductVo> getInfo(@NotNull(message = "主键不能为空")
                                                  @PathVariable("id") Long id) {
        return AjaxResult.success(iZsyyOrderProductService.queryById(id));
    }

    /**
     * 新增订单关联产品
     */
    @ApiOperation("新增订单关联产品")
    @PreAuthorize("@ss.hasPermi('system:orderProduct:add')")
    @Log(title = "订单关联产品", businessType = BusinessType.INSERT)
    @RepeatSubmit
    @PostMapping()
    public AjaxResult<Void> add(@Validated @RequestBody ZsyyOrderProductAddBo bo) {
        return toAjax(iZsyyOrderProductService.insertByAddBo(bo) ? 1 : 0);
    }

    /**
     * 修改订单关联产品
     */
    @ApiOperation("修改订单关联产品")
    @PreAuthorize("@ss.hasPermi('system:orderProduct:edit')")
    @Log(title = "订单关联产品", businessType = BusinessType.UPDATE)
    @RepeatSubmit
    @PutMapping()
    public AjaxResult<Void> edit(@Validated @RequestBody ZsyyOrderProductEditBo bo) {
        return toAjax(iZsyyOrderProductService.updateByEditBo(bo) ? 1 : 0);
    }

    /**
     * 删除订单关联产品
     */
    @ApiOperation("删除订单关联产品")
    @PreAuthorize("@ss.hasPermi('system:orderProduct:remove')")
    @Log(title = "订单关联产品" , businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult<Void> remove(@NotEmpty(message = "主键不能为空")
                                       @PathVariable Long[] ids) {
        return toAjax(iZsyyOrderProductService.deleteWithValidByIds(Arrays.asList(ids), true) ? 1 : 0);
    }
}
